import java.util.ArrayList;
import java.util.PriorityQueue;

import Matcher.JaccardMatcher;
import Matcher.MatchingResult;
import Matcher.MatchingResultComparator;
import documents.Document;
import documents.DocumentLibrary;
import utils.In;
import utils.Out;


public class main {

	public static void main(String[] args) {
		Out.println("Matching scores");
		
		DocumentLibrary library = new DocumentLibrary(true);
		JaccardMatcher matcher = new JaccardMatcher();
		//String[] filenames = {"test.txt"};
		String[] filenames = {"Macaria.txt", "test.txt", "TheMabinogion.txt"};
		
		//Lade TextDokumente
		library.addDocuments(filenames);
		
		Out.println(filenames.length+" Dokumente geladen");
		
		
		
		Out.println("Was willst du suchen? ");
		String query = In.readLine();
		Document queryDoc = new Document(query, true);
		
		
		Out.println("Starte Matcher");
		ArrayList<Document> docs = library.getDocuments();
		ArrayList<MatchingResult> results = new ArrayList<MatchingResult>();
		MatchingResultComparator comp = new MatchingResultComparator();
		PriorityQueue<MatchingResult> results2 = new PriorityQueue<MatchingResult>(1, comp);
		for(Document doc : docs) {
			float res = matcher.matchDocuments(queryDoc, doc);
			results.add(new MatchingResult(res, doc.getID()));
			results2.add(new MatchingResult(res, doc.getID()));
		}
		Out.println("Matcher fertig");
		
		
		Out.println("Ausgabe");
		for(MatchingResult mr : results) {
			Out.println("DocumentID: "+mr.getDocID()+" Value: "+mr.getValue());
		}
		
		Out.println("Ausgabe Queue");
		while (results2.size() != 0)
        {
			MatchingResult x = results2.poll();
            System.out.println("DocumentID: "+x.getDocID()+" Value: "+x.getValue());
        }
		
		
//		MatchingResult[] mr = new MatchingResult[0];
//		mr = results2.toArray(mr);
//		for(MatchingResult m : mr) {
//			Out.println("DocumentID: "+m.getDocID()+" Value: "+m.getValue());
//		}
	}

}
